<template>
  <div v-show="props.compType === 'colorPicker'">
    <el-form-item label="ID">
      <el-tooltip
        class="item"
        effect="dark"
        content="请注意,ID的修改可能会导致该组件相关事件失效！"
        placement="left"
      >
        <el-input v-model="props.id" class="input" @change="handlerChangeId"></el-input>
      </el-tooltip>
    </el-form-item>
    <el-form-item label="显示标签">
      <el-switch v-model="props.showLabel" @change="handlerShowLabel"></el-switch>
    </el-form-item>
    <el-form-item v-show="props.showLabel" label="标签文字">
      <el-input v-model="props.label" class="input"></el-input>
    </el-form-item>
    <el-form-item v-show="props.showLabel" label="标签长度">
      <el-input-number v-model="props.labelWidth" :min="1" :max="200"></el-input-number>
    </el-form-item>
    <el-form-item label="默认颜色">
      <el-color-picker v-model="props.modelValue" />
    </el-form-item>
    <el-form-item label="是否显示">
      <el-switch v-model="props.isShow"></el-switch>
    </el-form-item>
    <el-form-item label="禁用">
      <el-switch v-model="props.disabled"></el-switch>
    </el-form-item>
    <el-form-item label="大小">
      <el-radio-group v-model="props.size">
        <el-radio-button label="large">大</el-radio-button>
        <el-radio-button label="default">中</el-radio-button>
        <el-radio-button label="small">小</el-radio-button>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="预定义颜色">
      <div v-for="(item, index) in props.predefine" :key="item" class="select-item">
        <span class="el-color-picker__color"
          ><!--style="background-color: rgb(64, 158, 255);"-->
          <span class="el-color-picker__color-inner" :style="{ 'background-color': item }"> </span>
        </span>
        <div class="close-btn select-line-icon">
          <i class="el-icon-remove-outline" @click="handlerRemoveColor(index)" />
        </div>
      </div>
      <br />
      <el-color-picker v-model="color" @change="handlerAddPreColor"></el-color-picker>
    </el-form-item>
  </div>
</template>
<script>
  import { changeId } from '../mixin';
  export default {
    name: 'ButtonConfig',
    mixins: [changeId],
    props: {
      props: {},
    },
    data() {
      return {
        color: '#409EFF',
      };
    },
    mounted() {},
    methods: {
      handlerShowLabel(val) {
        if (val) {
          this.props.labelWidth = 80;
        } else {
          this.props.labelWidth = 0;
        }
      },
      handlerAddPreColor(val) {
        console.log(val);
        this.props.predefine.push(val);
        console.log(this.props.predefine);
      },
      handlerRemoveColor(index) {
        this.props.predefine.splice(index, 1);
      },
    },
  };
</script>
<style scoped>
  .el-color-picker__color {
    display: block;
    position: relative;
    box-sizing: border-box;
    width: 100px;
    height: 30px;
    margin-right: 2px;
    float: left;
    border: 1px solid #999;
    border-radius: 2px;
  }
</style>
